

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Compiler Design &mdash; Mosa Project  documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
        <script src="_static/jquery.js"></script>
        <script src="_static/underscore.js"></script>
        <script src="_static/doctools.js"></script>
        <script src="_static/language_data.js"></script>
    
    <script type="text/javascript" src="_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="_static/css/sphinx_prompt_css.css" type="text/css" />
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="Compiler Optimizations" href="compiler-optimizations.html" />
    <link rel="prev" title="Frequently Asked Questions (FAQs)" href="faq.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="index.html" class="icon icon-home"> Mosa Project
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">Introduction</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="introduction.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="getting-started.html">Getting Started</a></li>
<li class="toctree-l1"><a class="reference internal" href="demos.html">Demos</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="faq.html">Frequently Asked Questions (FAQs)</a></li>
</ul>
<p class="caption"><span class="caption-text">Compiler</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="current reference internal" href="#">Compiler Design</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#compiler-pipeline">Compiler Pipeline</a></li>
<li class="toctree-l2"><a class="reference internal" href="#method-compiler-pipeline">Method Compiler Pipeline</a></li>
<li class="toctree-l2"><a class="reference internal" href="#intermediate-representations">Intermediate Representations</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="compiler-optimizations.html">Compiler Optimizations</a></li>
<li class="toctree-l1"><a class="reference internal" href="compiler-transformations.html">Compiler Transformations</a></li>
</ul>
<p class="caption"><span class="caption-text">Settings</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="settings-options.html">Settings Options</a></li>
<li class="toctree-l1"><a class="reference internal" href="command-line-arguments.html">Command Line Arguments</a></li>
</ul>
<p class="caption"><span class="caption-text">Tools</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="tools.html">MOSA Tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="tool-compiler.html">MOSA Compiler</a></li>
<li class="toctree-l1"><a class="reference internal" href="tool-launcher.html">MOSA Launcher</a></li>
<li class="toctree-l1"><a class="reference internal" href="tool-launcher-console.html">MOSA Launcher Console</a></li>
<li class="toctree-l1"><a class="reference internal" href="tool-explorer.html">MOSA Explorer</a></li>
<li class="toctree-l1"><a class="reference internal" href="tool-debugger.html">MOSA Debugger</a></li>
<li class="toctree-l1"><a class="reference internal" href="tool-boot-image.html">MOSA Boot Image Tool</a></li>
</ul>
<p class="caption"><span class="caption-text">Advanced</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="unit-tests.html">Unit Tests</a></li>
<li class="toctree-l1"><a class="reference internal" href="usb-flash-drive-installation.html">USB Flash Drive Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="baremetal.html">BareMetal Experiment</a></li>
</ul>
<p class="caption"><span class="caption-text">Contribute</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="get-involved.html">Get Involved</a></li>
<li class="toctree-l1"><a class="reference internal" href="authors.html">Authors</a></li>
<li class="toctree-l1"><a class="reference internal" href="license.html">License</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="index.html">Mosa Project</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="index.html">Docs</a> &raquo;</li>
        
      <li>Compiler Design</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="_sources/compiler-design.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="compiler-design">
<h1>Compiler Design<a class="headerlink" href="#compiler-design" title="Permalink to this headline">¶</a></h1>
<p>The MOSA Compiler framework is designed around two pipelines each with multiple stages.</p>
<div class="section" id="compiler-pipeline">
<h2>Compiler Pipeline<a class="headerlink" href="#compiler-pipeline" title="Permalink to this headline">¶</a></h2>
<p>The <strong>Compiler Pipeline</strong> is the primary pipeline that executes the steps necessary to compile an application, such as building the type system, compiling each method, linking, and emitting the final object file.</p>
<p>One stage executes the <strong>Method Compiler Pipeline</strong> for each method in the application.</p>
</div>
<div class="section" id="method-compiler-pipeline">
<h2>Method Compiler Pipeline<a class="headerlink" href="#method-compiler-pipeline" title="Permalink to this headline">¶</a></h2>
<p>The <strong>Method Compiler Pipeline</strong> is used to compile a single method by progressively lowers the high level instruction representation to the final opcode instructions of the target platform. This pipeline is executed at least once for all methods in the application.</p>
<p>All the stages can be grouped into one or more of these categories:</p>
<dl class="simple">
<dt>Decoding Stage</dt><dd><p>Creates an instruction stream for a method from the source representation, such as a method from a .NET application</p>
</dd>
<dt>Transformation Stages</dt><dd><p>Transforms the instruction stream between various representations, usually from a higher level to a lower level representations</p>
</dd>
<dt>Optimization Stages</dt><dd><p>Transforms instructions intended to optimize the code to execute faster</p>
</dd>
<dt>Register Allocation Stage</dt><dd><p>Allocates the virtual registers in the instruction stream to platform specific physical registers</p>
</dd>
<dt>Platform Specific Transformation Stages</dt><dd><p>Transforms the instructions in the stream into specific platform opcodes</p>
</dd>
</dl>
</div>
<div class="section" id="intermediate-representations">
<h2>Intermediate Representations<a class="headerlink" href="#intermediate-representations" title="Permalink to this headline">¶</a></h2>
<p>The compiler framework uses a linear intermediate representation (vs an expression tree) to transform the source application into binary machine code. There are several levels of intermediate representations before code generation. These are:</p>
<ul class="simple">
<li><p>Common Intermediate Language (CIL)</p></li>
<li><p>High-Level Intermediate Representation (IR)</p></li>
<li><p>Machine specific Intermediate Representation (MIR)</p></li>
</ul>
<p>During compilation of an CIL method the instructions are represented by CIL instruction classes and moving forward, the linear instruction stream is modified to use instructions from the intermediate representation. In some cases an instruction from the intermediate representation can not be emitted directly to machine code and it is replaced by a sequence of machine specific instructions. The machine specific instruction classes are provided by the appropriate platform.</p>
</div>
</div>


           </div>
           
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="compiler-optimizations.html" class="btn btn-neutral float-right" title="Compiler Optimizations" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="faq.html" class="btn btn-neutral float-left" title="Frequently Asked Questions (FAQs)" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2008-2020, Mosa Project &amp; contributors

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>